/**
 * Created by Administrator on 2015/8/21.
 */

var React = require('react');
var Trades = require('./Trades');


module.exports = TradesApp = React.createClass({

    getInitialState: function(props){
        return {
            trades: [],
            count: 0,
            page: 0,
            paging: false,
            skip: 0,
            done: false
        };

    },
    addTrade: function(trade){
        var updated = this.state.trades;
        updated.unshift(trade);
        console.log("消息数组：：： " + updated);
        this.setState({trades: updated});

    },
    componentDidMount: function(){
        var self = this;
        var socket = io.connect();
        //var socket = io('http://localhost:3000');
        socket.on('connection', function() {
            console.log('connection setup for socket.io')
        });
        socket.on('jeanBusy', function (data) {
            console.log('get message:'+data)
            self.addTrade(JSON.parse(data));
        });
    },
    render: function(){

        return (
            <div id="content">
                <div id="waterfall" className="waterfall">
                    <Trades trades={this.state.trades} />
                </div>
            </div>
        )

    }

});